package com.hospitalsystem.controller;

import com.hospitalsystem.entity.MedicalRecord;
import com.hospitalsystem.service.MedicalRecordService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (MedicalRecord)表控制层
 *
 * @author makejava
 * @since 2024-12-28 19:32:48
 */
@RestController
@RequestMapping("medicalRecord")
public class MedicalRecordController {
    /**
     * 服务对象
     */
    @Resource
    private MedicalRecordService medicalRecordService;

    /**
     * 分页查询
     *
     * @param medicalRecord 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<MedicalRecord>> queryByPage(MedicalRecord medicalRecord, PageRequest pageRequest) {
        return ResponseEntity.ok(this.medicalRecordService.queryByPage(medicalRecord, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param mId
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<MedicalRecord> queryById(@PathVariable("id")String mId) {
        return ResponseEntity.ok(this.medicalRecordService.queryById(mId));
    }

    /**
     * 新增数据
     *
     * @param medicalRecord 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<MedicalRecord> add(MedicalRecord medicalRecord) {
        return ResponseEntity.ok(this.medicalRecordService.insert(medicalRecord));
    }

    /**
     * 编辑数据
     *
     * @param medicalRecord 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<MedicalRecord> edit(MedicalRecord medicalRecord) {
        return ResponseEntity.ok(this.medicalRecordService.update(medicalRecord));
    }

    /**
     * 删除数据
     *
     * @param mId
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(String mId) {
        return ResponseEntity.ok(this.medicalRecordService.deleteById(mId));
    }

}

